package com.six.core.controller;

import com.six.core.entity.Role;
import com.six.core.service.RoleService;
import com.six.core.vo.EmpRoleVo;
import com.six.core.vo.Result;
import com.six.core.vo.RoleNameVo;
import com.six.core.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @author:LiWei
 * @date:2023年02月27日18:52
 */
@Api(value = "/system/role", tags = {"aaaaaaaaaaaaaaa"})
@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "RoleVo", name = "roleVo", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("list/{currentPage}/{pageSize}")
    public Result list(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody RoleVo roleVo){
        Result all = roleService.findAll(currentPage, pageSize, roleVo);
        return new Result(200,"查询成功",all);

    }

    //根据角色名查询权限
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "RoleNameVo", name = "roleNameVo", value = "", required = true)
    })
    @ApiOperation(value = "根据角色名查询", notes = "根据角色名查询")
    @RequestMapping("findByRoleName/{currentPage}/{pageSize}")
    public Result findByRoleName(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody RoleNameVo roleNameVo){
        String roleName = roleNameVo.getRoleName();
        return roleService.findByRoleName(currentPage,pageSize,roleName);

    }


    // 根据用户id查询权限角色
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "roleId", value = "", required = true)
    })
    @ApiOperation(value = "根据用户id查询", notes = "根据用户id查询", httpMethod = "GET")
    @GetMapping("findByUserId/{userId}")
    public Result findByUserId(Integer roleId){
        System.out.println("userId = " + roleId);
        return roleService.findByUserId(roleId);
    }


    //  根据用户id所具有的管理员权限分配员工角色
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EmpRoleVo", name = "empRoleVo", value = "", required = true)
    })
    @ApiOperation(value = "根据用户id所具有的管理员权限分配员工角色", notes = "根据用户id所具有的管理员权限分配员工角色", httpMethod = "POST")
    @PostMapping("fenRole")
    public Result fenRole(@RequestBody EmpRoleVo empRoleVo){
       return  roleService.fenRole(empRoleVo);
    }


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "roleid", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("deleteByRoleId/{roleid}")
    public Result deleteByRoleId(@PathVariable Integer roleid){
        return roleService.deleteRoleById(roleid);

    }


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Role", name = "role", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("/updateRole")
    private Result updateRole(@RequestBody Role role){
        return roleService.updateRole(role);
    }


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "roleId", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("/findPermissionByRoleId/{roleId}")
    private Result findPermissionByRoleId(@PathVariable Integer roleId){
        return roleService.findPermissionByRoleId(roleId);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Role", name = "role", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("/addRole")
    public Result addRole(@RequestBody Role role){
        return roleService.addRole(role);
    }




}













